﻿using System.Collections.Generic;

namespace xxpl.Utils
{

    public class Guard
    {
        static readonly List<string> H2HHeaders = new List<string> { "connection", "keep-alive",
			"proxy-authenticate", "proxy-authorization", "te", "trailers",
			"transfer-encoding", "upgrade","content-length" };

        static readonly List<string> ForbidHeaders = new List<string> { "if-range" };

        public static bool IsSafeHeader(string header)
        {
            if (string.IsNullOrEmpty(header))
            {
                return false;
            }
            if(H2HHeaders.Contains(header.ToLower()))
            {
                return false;
            } 
            if (ForbidHeaders.Contains(header.ToLower()))
            {
                return false;
            }
            
            return true;
        }

        public static bool IsAllowedMethod(string methodName)
        {
            if (string.IsNullOrEmpty(methodName))
            {
                return false;
            }

           string  method = methodName.ToUpper();

           return method == "GET" || method == "HEAD" || method == "POST";
        }

        public static bool IsAllowedProtocol(string methodName)
        {
            if (string.IsNullOrEmpty(methodName))
            {
                return false;
            }

            string method = methodName.ToUpper();

            return method == "HTTP" || method == "HTTPS";
        }
    }

}
